<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('核销类型')}:</label>
        <div class="col-xs-12 col-sm-8">
            <label class="radio-inline">
                <input type="radio" name="type" value="2" id="type-store" <?php if ($row['spot']['type'] == 2) echo 'checked'; ?>> {:__('门店核销员')}
            </label>
            <label class="radio-inline">
                <input type="radio" name="type" value="1" id="type-pickup" <?php if ($row['spot']['type'] == 1) echo 'checked'; ?>> {:__('自提点核销员')}
            </label>
        </div>
    </div>
    <div class="form-group type-2">
        <label class="control-label col-xs-12 col-sm-2">{:__('选择门店')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-store-selector"
                   data-source="wanlshop.verification/shop"
                   data-multiple="true"
                   data-pagination="true"
                   data-page-size="1"
                   class="form-control selectpage"
                   name="row[address_spot_id]"
                   type="text"
                   data-params='{"type":2}'
                   value="{$row.address_spot_id|htmlentities}">
        </div>
    </div>
    <div class="form-group type-1" style="display: none;">
        <label class="control-label col-xs-12 col-sm-2">{:__('选择自提点')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-pickup-selector"
                   data-source="wanlshop.verification/shop"
                   data-multiple="true"
                   data-pagination="true"
                   data-page-size="1"
                   class="form-control selectpage"
                   name="row[address_spot_id]"
                   type="text"
                   data-params='{"type":1}'
                   value="{$row.address_spot_id|htmlentities}">
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>

        </div>
    </div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<script>
    $(document).ready(function() {

        // 初始化时根据默认选中的type值显示对应的输入框
        var selectedType = $('input[name="type"]:checked').val();
        toggleInputFields(selectedType);

        // 监听type变化
        $('input[name="type"]').change(function () {
            var selectedType = $(this).val();
            toggleInputFields(selectedType);
        });

        // 根据type显示对应的输入框
        function toggleInputFields(type) {
            if (type == '2') {
                $('.type-1').hide();
                $('.type-2').show();
            } else if (type == '1') {
                $('.type-2').hide();
                $('.type-1').show();
            }
        }
    });
</script>
